
public class IfClause extends AbstractElement {
	
	public IfClause() {
		this.type = "If";
		this.value = "If";
	}

	
	public Object interpret(RobotActions robot) {
		
		Object result = null;
		
		if(filhos.size()<2) {
			System.err.println("IfClause.interpret: Wrong arguments for if clause");
			return null;
		}
			
		Object clause_result = this.filhos.get(0).interpret(robot);
		
		try {
		

		if (clause_result != null && !(new Integer(0)).equals(clause_result))
			result = this.filhos.get(1).interpret(robot);
		else if(filhos.size() == 3)
			result = this.filhos.get(2).interpret(robot);
		}
		
		catch (Exception e) {
			System.err.println("IfClause.interpret: An error has ocurred while processing IfClause");
			return null;
		}
		
		return result;
	}
	
	

}
